var express = require('express');
var router = express.Router();
let onlineArr = {};

router.post('/isOnline', function(req, res, next) {
    console.log("isOnline====body==",req.body);
    if(!onlineArr[req.body.openid]){
        onlineArr[req.body.openid] = {timeStamp:0,pushNum:1};
        return res.json({code:1,pushNum:0});
    }else{
        let temp = Date.now() - onlineArr[req.body.openid].timeStamp;
        if(temp >= 120000){
            onlineArr[req.body.openid].pushNum = onlineArr[req.body.openid].pushNum +1;
            return res.json({code:1,pushNum:onlineArr[req.body.openid].pushNum});
        }else{
            onlineArr[req.body.openid].pushNum = 0;
            res.json({code:0});
        }
    }
});

router.post('/online', function(req, res, next) {
    onlineArr[req.body.openid] = {timeStamp:Date.now(),pushNum:0};
    res.json({code:0});
});

router.options('/online', function(req, res, next) {
    res.send({code:0});
});
module.exports = router;
